<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<link href="./css/dtree.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/dtree-permit.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var roleName = document.getElementById("roleName");
		var roleDesc = document.getElementById("roleDesc");
		
		var functionIds = document.getElementsByName("ck");
		
		if(roleName.value == ""){
			alert("<fmt:message key='role.lable.roleName'/><fmt:message key='common.message.empty'/>");
			return false;
		}
		if(roleDesc.value == ""){
			alert("<fmt:message key='role.lable.roleDesc'/><fmt:message key='common.message.empty'/>");
			return false;
		}
		
		var sign = 0;
		for(var i = 0; i < functionIds.length; i++){
			if(functionIds[i].checked)sign = sign + 1;
		}
		
		if(sign <= 0){
			alert("<fmt:message key='role.message.function'/>");
			return false;
		}
		return true;
	}

	function back(){
		window.location.href = "./role.do";
		window.location.target = "main";
	}
	
	function update(){
		if(checkForm()){
			document.updateRoleForm.action = "./role.do?action=updateViewRole";
			document.updateRoleForm.target = "main";
			document.updateRoleForm.submit();
		}
	}
	
	function selectCheckbox(funcOperateIds){
		if(funcOperateIds != ""){
			var cFunctionIds = document.getElementsByName("ck");
			var functionIds = funcOperateIds.split(",");
			for(var i = 0; i < cFunctionIds.length; i++){
				for(var j = 0; j < functionIds.length; j++){
					if(cFunctionIds[i].value == functionIds[j]){
						cFunctionIds[i].checked = true;
					}
				}
			}
		}
	}
	
	function initPage(result,repeat,funcOperateIds){
		if(result == 1){
			alert("<fmt:message key='common.message.updateSuccess'/>");
		}
		if(repeat == 1){
			alert("<fmt:message key='common.message.updateFail'/><fmt:message key='role.lable.roleName'/><fmt:message key='common.message.exist'/>");
		}
		
		selectCheckbox(funcOperateIds);
	}
	
-->
</script>
</head>
<body onload="initPage('${result}','${repeat}','${funcOperateIds}')">
<form name="updateRoleForm" action="" method="post">
	<table class="table_frame" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table class="table_title" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title_lab" colspan="3">
							&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key='role.title.update'/>
						</td>
					</tr>
					<tr><td height="15"></td></tr>
					<tr>
						<td valign="bottom">&nbsp;
							<a href="javascript:update();" title="<fmt:message key='common.button.save'/>" hidefocus="true"><fmt:message key='common.button.save'/></a>
						</td>
						<td valign="bottom" align="right">
							<a href="javascript:back();" title="<fmt:message key='common.button.back'/>" hidefocus="true"><fmt:message key='common.button.back'/></a>&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="5"></td>
		</tr>
		<tr>
			<td>
				<table class="table1">
					<tr>
						<td valign="top" width="">
							<table class="table_input" cellpadding="0" cellspacing="0" style="margin: 0 0 0 100px;">
								<tr>
									<td class="title3" width="15%"><fmt:message key='role.lable.roleCode'/><fmt:message key='common.sign'/><input id="id" name="id" type="hidden" value="${role.id}"/></td>
									<td class="title3">${role.roleCode}<input id="roleCode" name="roleCode" type="hidden" value="${role.roleCode}"/></td>
								</tr>
								<tr>
									<td class="title3" width="15%"><fmt:message key='role.lable.roleName'/><fmt:message key='common.sign'/></td>
									<td class="title3" width="">
										<input id="roleName" name="roleName" class="input_long" type="text" value="${role.roleName}"/>
									</td>
								</tr>
								<tr>
									<td class="title3" width="15%"><fmt:message key='role.lable.roleDesc'/><fmt:message key='common.sign'/></td>
									<td class="title3" width="">
										<input id="roleDesc" name="roleDesc" class="input_long" type="text" value="${role.roleDesc}"/>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td valign="top" style="border-top: solid 1px #94b8e9;"><font style="height: 30px;"></font>
							<table class="table_input" cellpadding="0" cellspacing="0" style="margin: 0 0 0 100px;">
								<tr><td>定义桌面</td></tr>
								<tr>
									<td class="title3">
										
										<table>
										<c:forEach var="function" items="${functions}">
										
										
										<tr>
										<td>..</td>
										<td>${function.viewName }</td>
										<td><input type="checkbox" name="ck" value="${function.id }"/></td>
										</tr>
										
											
										
										</c:forEach>
										</table>
									
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>